<template>
            <r-l-list ref="dylist" listItemName="RepositoryItem" :listData="dataList" :listHeight="listHeight"
                      :forLoadMore="onLoadMore" :forRefresh="onRefresh" :itemClick="itemClick">
            </r-l-list>
</template>

<script>
    const modal = weex.requireModule('modal')

    import {Utils} from 'weex-ui'
    import RLList from './widget/RLList.vue'
    import { getListHeight} from '../config/Config'
    import * as Config from '../config/Config'


    export default {
        components: {RLList},
        data() {
            return {
                currentPage: 1,
                since:null,
                languageType:null,
                listHeight: getListHeight(Utils.env.getScreenHeight() , Utils),
                primaryColor:Config.primaryColor,
            }
        },
        created: function () {
            this.onRefresh();
        },
        activated: function () {
            //keep alive
            if(WXEnvironment.platform === 'Web') {
                this.onRefresh();
            }
        },
        computed: {
            dataList() {
                return this.$store.state.repository.trend_repos_data_list;
            },
        },
        methods: {
            loadData(type) {
                this.$store.dispatch('getContent', {
                    page: this.currentPage,
                    callback: (res) => {
                      if (type === 1) {
                        if (this.$refs.dylist) {
                          this.$refs.dylist.stopRefresh();
                        }
                      } else if (type === 2) {
                        if (this.$refs.dylist) {
                          this.$refs.dylist.stopLoadMore();
                        }
                      }
                      if (this.$refs.dylist) {
                        if (!res.data || res.data.length < this.getPageSize()) {
                          this.$refs.dylist.setNotNeedLoadMore();
                        } else {
                          this.$refs.dylist.setNeedLoadMore();
                        }
                      }
                    },
                })
            },
            onLoadMore() {
                // if (this.$refs.dylist) {
                //     this.$refs.dylist.setNotNeedLoadMore();
                // }
              this.currentPage++;
              this.loadData(2)
            },
            onRefresh() {
                this.loadData(1);
            },
            itemClick(index) {
                let data = this.dataList[index]
                this.jumpWithParams("WebPage", {
                    url: `http://user.test.yarsenal.com/app/content/${data.id}`
                })
            }
        }
    }
</script>


<style lang="scss" >
    @import '../config/styles.scss';

    .title-container {
        position: absolute;
        left: 0;
        right: 0;
        flex-direction: row;
        width: 750px;
        height: 80px;
        padding: 10px 20px;
        Align-items: center;
        justify-content: center;
        background-color: white;
        z-index: 999;
        box-shadow: $--box-shadow-color;
        border-bottom-left-radius: 10px;
        border-bottom-right-radius: 10px;
    }
</style>
<style scoped>
    /*.list-container {*/
        /*margin-top: 80px;*/
    /*}*/
</style>
